﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace yule.CodeBuilder.Core
{
    /// <summary>
    /// 下载辅助类
    /// </summary>
    public static class DownLoadHelper
    {
        /// <summary>
        /// 文本格式(text/plain)
        /// </summary>
        public static readonly string CONTENTTYPE_TEXT = "text/plain";

        /// <summary>
        /// 创建下载
        /// </summary>
        /// <param name="content">下载内容</param>
        /// <param name="fileDownFileName">下载文件名</param>
        /// <param name="contentType">下载内容类型</param>
        /// <returns></returns>
        public static FileContentResult CreateDownLoad(string content, string fileDownFileName, string contentType)
        {
            byte[] bytes = System.Text.UTF8Encoding.UTF8.GetBytes(content);
            FileContentResult fcr = new FileContentResult(bytes, contentType);
            fcr.FileDownloadName = fileDownFileName;
            //可以顺带清理下。防止影响此文件下载
            System.Web.HttpContext.Current.Response.Clear();
            return fcr;
        }

    }
}